package kafeisc.utils;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Classname ${NAME}
 * @Description TODO
 * @Date 21:42
 * @Created 
 */
@WebServlet(name = "CheckImageServlet")
public class CheckImageServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("image/jpeg;utf-8");
        // 1. 获取验证码图片
        YanZhengMa vf = new YanZhengMa();
        BufferedImage iamge = vf.getImage();
        // 2. 得到验证的四个随机数
        String code = vf.getText();
        // 为了进行验证码校验
        request.getSession().setAttribute("serverCode",code);
        // 3. 把生成的验证码图片输入到页面
        YanZhengMa.output(iamge,response.getOutputStream());

    }
}
